package com.example.sys.speciality.mapping;

import com.example.core.constant.Constant;
import com.example.core.mapping.BaseMapping;
import com.example.core.utils.StringUtils;
import com.example.sys.speciality.po.SysSpecialityCategory;
import com.example.sys.speciality.service.SysSpecialityCategoryService;
import com.example.sys.speciality.vo.SysSpecialityCategoryVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysSpecialityCategoryMapping extends BaseMapping<SysSpecialityCategory, SysSpecialityCategoryVo> {

    @Resource
    private SysSpecialityCategoryService sysSpecialityCategoryService;

    @Override
    public void toPo(SysSpecialityCategoryVo vo, SysSpecialityCategory po) throws Exception {
        if (StringUtils.isEmpty(vo.getParentId())) {
            po.setHierarchy(Constant.X + po.getId() + Constant.X);
        } else {
            SysSpecialityCategory sysSpecialityCategory = this.sysSpecialityCategoryService.getById(vo.getParentId());
            if (sysSpecialityCategory != null) {
                po.setParentName(sysSpecialityCategory.getName());
                po.setHierarchy(sysSpecialityCategory.getHierarchy() + po.getId() + Constant.X);
            }
        }
    }
}
